jQ(function(){
	jQ("button").attr("hidefocus",true);
	jQ("#subscribetabs a").unbind("click").bind("click",function(){
		if(jQ(this).hasClass("onit"))
			return;
		else{
			jQ("#subscribetabs a.onit").removeClass("onit");
			jQ("#subscribetabs").data("currentpage",0);
			jQ("#subscribetabs").removeData("currentdate");
			if(jQ(this).hasClass("mysubscribe")){
				jQ("#calendardate_choose").show();
				jQ("#subscribetabs").bind("load",loadMySubscribes);
				loadMySubscribes();
				jQ("#calendardate_choose button.yesterday").unbind("click").bind("click",prevDateClick);
				jQ("#calendardate_choose button.tomorrow").unbind("click").bind("click",nextDateClick);
			}else{
				jQ("#calendardate_choose").hide();
				jQ("#subscribetabs").bind("load",loadMoreSubscribes);
				loadMoreSubscribes();
				jQ("#calendardate_choose button.yesterday").unbind("click");
				jQ("#calendardate_choose button.tomorrow").unbind("click");
			}
			jQ(this).addClass("onit");
		}
	});
	jQ("#subscribetabs").data("currentpage",0);
	jQ("#calendardate_choose").show();
	jQ("#subscribetabs").bind("load",loadMySubscribes);
	loadMySubscribes();
	jQ("#calendardate_choose button.yesterday").unbind("click").bind("click",prevDateClick);
	jQ("#calendardate_choose button.tomorrow").unbind("click").bind("click",nextDateClick);
	initContacts();
});

function loadMySubscribes(){
	var currentdate=jQ("#subscribetabs").data("currentdate");
	var year,month,date;
	if(typeof(currentdate)=='undefined'||currentdate==null){
		year=0;
		month=0;
		date=0;
	}else{
		year=currentdate.getFullYear();
		month=currentdate.getMonth();
		date=currentdate.getDate();
	}
	var currentpage=jQ("#subscribetabs").data("currentpage");
	jQ.ajax({
		type: "POST",
		url:"eventAjax!loadUserAllSubscribeEvents.action",
		data:{
			year:year,
			month:month,
			date:date,
			currentpage:currentpage
		},
		success:function(data){
			var datetime=eval(jQ(data).find("datetime").text());
			var dateobj=new Date();
			dateobj.setTime(datetime);
			jQ("#subscribetabs").data("currentdate",dateobj);
			jQ("#calendardate_choose span").empty().append(formateTime(datetime));
			var pagecount=eval(jQ(data).find("pagecount").text());
			initPaging(currentpage,pagecount);
			var html="";
			if(jQ(data).find("ClipEvent").length==0){
				html+="<tr>" +
						"<td colspan=3>"+
						"当日无订阅档期，是否想去<a onclick='jQ(\"#subscribetabs a.more\").click();'>档期推荐</a>看看那？"+
						"</td>"+
						"</tr>";
				jQ("#clip_content").empty().append(html);
				return;
			}
			jQ(data).find("ClipEvent").each(function(){
				var eventid=eval(jQ(this).attr("id"));
				var uname=jQ(this).find("uname").text();
				var unameid=jQ(this).find("unameid").text();
				var unamelogo=jQ(this).find("unamelogo").text();
				var unameslogo=jQ(this).find("unameslogo").text();
				var seid=eval(jQ(this).find("seid").text());
				var shareid=jQ(this).find("shareid").text();
				var title=jQ(this).find("title").text();
				var starttime=jQ(this).find("starttime").text();
				var endtime=jQ(this).find("endtime").text();
				var iswholeday=jQ(this).find("iswholeday").text();
				var content=jQ(this).find("content").text();
				var clocktime=jQ(this).find("clocktime").text();
				var clipeventpic=jQ(this).find("clipeventpic").text();
				
				var favorcount=jQ(this).find("favorcount").text();
				var clipmsgcount=jQ(this).find("clipmsgcount").text();
				var interestcount=jQ(this).find("interestcount").text();
				var isinterest=eval(jQ(this).find("isinterest").text());
				var isfavor=eval(jQ(this).find("isfavor").text());
				var deadlinetime=jQ(this).find("deadlinetime").text();
				var address=jQ(this).find("address").text();
				var iscanfw=eval(jQ(this).find("iscanfw").text());
				html+="<tr eventid='"+eventid+"'>";
					html+="<td class=\"avatar\">";
						html+="<div class=\"logo\" style=\"background:url('"+unameslogo+"')\" title='"+uname+"'>" +
								"<a href='"+jQ("#ctxVal").val()+"/myclip/user.html?"+unameid+"'></a>" +
								"</div>";
						html+="<a class=\"cancelss\" uid="+unameid+"></a>";
					html+="</td>";
					html+="<td class=\"theme\">";
					html+="<input class=\"shareid\" type=\"hidden\" value=\""+shareid+"\" />";
					html+="<input class=\"title\" type=\"hidden\" value=\""+title+"\" />";
					html+="<input class=\"starttime\" type=\"hidden\" value=\""+starttime+"\" />";
					html+="<div class=\"ssname\"><a href='"+jQ("#ctxVal").val()+"/myclip/user.html?"+unameid+"'>"+uname+"</a></div>";
					html+="<div class=\"time\">";
						html+="<span class=\"a\">活动时间：</span>";
						if(iswholeday){
							html+="<span>开始于&nbsp;</span>";
							html+="<b>"+formateDetailTime(starttime)+"</b>";
						}else{
							html+="<b>"+formateDetailTime(starttime)+"</b>";
							html+="<span>&nbsp;至&nbsp;</span>";
							html+="<b>"+formateDetailTime(endtime)+"</b>";
						}
					html+="</div>";
					if(deadlinetime!=null&&eval(deadlinetime)>0){
						html+="<div class=\"time\">";
						html+="<span class=\"a\">截止时间：</span>";
						html+="<b>"+formateDetailTime(eval(deadlinetime))+"</b>";
						html+="</div>";
					}
					html+="<div class=\"topic\">";
						html+="<span class=\"a\">内容：</span>";
						html+="<span class=\"name\">"+title+"</a>";
					html+="</div>";
					if(address!=null&&address.length>0){
						html+="<div class=\"topic\">";
							html+="<span class=\"a\">地址：</span>";
							html+="<span class=\"name\">"+address+"</a>";
						html+="</div>";
					}
					if((content!=null&&content.length>0)||(clipeventpic!=null&&clipeventpic.length>0)){
						html+="<div class=\"txt\">";
						html+="<span class=\"a\">详情：</span>";
						if(content!=null&&content.length>0){
							html+="<span class=\"val\">";
							html+=content;
							html+="</span>";
						}
						if(clipeventpic!=null&&clipeventpic.length>0){
							html+="<div class=\"picture w_clippic bigcursor\">";
								html+="<input type='hidden' value='"+clipeventpic+"'/>";
								html+="<img class='bigcursor' onload='resizeImgCSS(this);' src='"+jQ("#ctxVal").val()+"/clippic/S_"+clipeventpic+"'>";
							html+="</div>";
						}
						html+="</div>";
					}
					html+="<div class=\"opt\">";
					
					html+=getInterestBtnHTML(isinterest,interestcount);
					html+="<a class='comment' count='"+clipmsgcount+"'>评论("+clipmsgcount+")</a>";
					html+=getFavorBtnHTML(isfavor,favorcount);
					if(iscanfw)
						html+="<a class='forward' onclick='showForwardEvent(this);'>呼朋唤友</a>";
					if(isinterest){
						if(clocktime>0){
							html+="<div class=\"setclock onedit\">";
							html+="<div class=\"middle\">";
							html+="<i class=\"clock\"></i>";
							html+="<span class=\"timedata\">"+formateDetailTime(clocktime)+"</span>";
							html+="<a class=\"cancel\"></a>";
							html+="</div>";
							html+="</div>";
						}else{
							html+="<div class=\"setclock\">";
							html+="<div class=\"middle\">";
							html+="<i class=\"clockoff\"></i>";
							html+="<a class=\"timeset\">设置提醒</a>";
							html+="</div>";
							html+="</div>";
						}
					}
					html+="</div>";
					html+="<div class=\"commentline\" style=\"display: none;\">";
					html+="<input type=\"text\"><button onclick=\"addNewComment(this);\" class=\"commentbtn\"></button>";
					html+="</div>";
					if(iscanfw){
						html+="<div class=\"shareoutzone\">";
						html+="<div class=\"shareoutopt\">";
						html+="<span class=\"shareouttxt\">分享到站外：</span>";
						html+="<a class=\"sinalogo\"></a>";
						html+="<a class=\"weixinlogo\"></a>";
						html+="<a class=\"tqqlogo\"></a>";
						html+="<a class=\"renrenlogo\"></a>";
						html+="<a class=\"kaixin001logo\"></a>";
						html+="<a class=\"doubanlogo\"></a>";
						html+="</div>";
						html+="<div class=\"shareoutcopy\">";
						var tmpurl="http://"+document.domain+jQ("#ctxVal").val()+"/myclip/clip_detail.html?"+shareid;
						html+="<input disabled=\"disabled\" id=\"shareoutcopy_ipt_"+eventid+"\" value='"+tmpurl+"'>";
						html+="<button id=\"shareoutcopy_btn_"+eventid+"\" data-clipboard-target=\"shareoutcopy_ipt_"+eventid+"\"></button>";
						html+="</div>";
						html+="</div>";
					}
					html+="</td>";
					html+="<td class=\"like\">";
						html+="<a class=\"detail\" target='_blank' href='"+jQ("#ctxVal").val()+"/myclip/clip_detail.html?"+shareid+"'></a>";
					html+="</td>";
				html+="</tr>";
			});
			jQ("#clip_content").empty().append(html);
			jQ("#clip_content tr td.avatar").find("a.cancelss").unbind("click").bind("click",cancelSubscribe);
			var tdthemeobj=jQ("#clip_content tr td.theme");
			tdthemeobj.find("div.opt div.setclock").find("div.middle a.timeset").unbind("click").bind("click",setclockClipevent);
			tdthemeobj.find("div.opt div.setclock").find("div.middle a.cancel").unbind("click").bind("click",cancelClockevent);
			tdthemeobj.find("div.opt a.interest").unbind("click").bind("click",uninterestClipevent);
			tdthemeobj.find("div.opt a.uninterest").unbind("click").bind("click",interestClipevent);
			tdthemeobj.find("div.opt a.comment").unbind("click").bind("click",showCommentEvent);
			tdthemeobj.find("div.opt a.unfavor").unbind("click").bind("click",favorClipevent);
			tdthemeobj.find("div.opt a.favor").unbind("click").bind("click",unfavorClipevent);
			tdthemeobj.find("div.txt div.picture").unbind("click").bind("click",showClipeventpic);
			
			tdthemeobj.find("div.shareoutzone div.shareoutcopy").find("button").each(function(){
				var idstr=jQ(this).prev().attr("id");
				jQ(this).attr("data-clipboard-target",idstr);
				var tempclip=new ZeroClipboard( document.getElementById(jQ(this).attr("id")), {
					moviePath: jQ("#ctxVal").val()+"/js/common/ZeroClipboard.swf",
					positionStyle:"absolute"
				} );
				tempclip.addEventListener("complete",function(){
					copyOptReturnBox(jQ("#"+jQ(this).attr("id")),"复制成功");
				});
			});
			
			initShareOutofSiteATDetail(tdthemeobj);
		}
	});
}

function loadMoreSubscribes(){
	var currentpage=jQ("#subscribetabs").data("currentpage");
	jQ.ajax({
		type: "POST",
		url:"eventAjax!loadClipRecommends.action",
		data:{
			currentpage:currentpage
		},
		success:function(data){
			var pagecount=eval(jQ(data).find("pagecount").text());
			initPaging(currentpage,pagecount);
			var html="";
			if(jQ(data).find("ClipEvent").length==0){
				html+="<tr>" +
						"<td colspan=3>"+
						"暂无推荐档期"+
						"</td>"+
						"</tr>";
				jQ("#clip_content").empty().append(html);
				return;
			}
			jQ(data).find("ClipEvent").each(function(){
				var eventid=eval(jQ(this).attr("id"));
				var uname=jQ(this).find("uname").text();
				var unameid=jQ(this).find("unameid").text();
				var unamelogo=jQ(this).find("unamelogo").text();
				var unameslogo=jQ(this).find("unameslogo").text();
				var seid=eval(jQ(this).find("seid").text());
				var shareid=jQ(this).find("shareid").text();
				var title=jQ(this).find("title").text();
				var starttime=jQ(this).find("starttime").text();
				var endtime=jQ(this).find("endtime").text();
				var iswholeday=jQ(this).find("iswholeday").text();
				var content=jQ(this).find("content").text();
				var clocktime=jQ(this).find("clocktime").text();
				var clipeventpic=jQ(this).find("clipeventpic").text();
				
				var favorcount=jQ(this).find("favorcount").text();
				var clipmsgcount=jQ(this).find("clipmsgcount").text();
				var interestcount=jQ(this).find("interestcount").text();
				var isinterest=eval(jQ(this).find("isinterest").text());
				var isfavor=eval(jQ(this).find("isfavor").text());
				
				var issubscribed=eval(jQ(this).find("issubscribed").text());
				var deadlinetime=jQ(this).find("deadlinetime").text();
				var address=jQ(this).find("address").text();
				var iscanfw=eval(jQ(this).find("iscanfw").text());
				html+="<tr eventid='"+eventid+"'>";
					html+="<td class=\"avatar\">";
						html+="<div class=\"logo\" style=\"background:url('"+unameslogo+"')\" title='"+uname+"'>" +
								"<a href='"+jQ("#ctxVal").val()+"/myclip/user.html?"+unameid+"'></a>" +
								"</div>";
						if(issubscribed)
							html+="<a class=\"cancelss\" uid="+unameid+"></a>";
						else
							html+="<a class=\"ssbtn\" uid="+unameid+"></a>";
					html+="</td>";
					html+="<td class=\"theme\">";
					html+="<input class=\"shareid\" type=\"hidden\" value=\""+shareid+"\" />";
					html+="<input class=\"title\" type=\"hidden\" value=\""+title+"\" />";
					html+="<input class=\"starttime\" type=\"hidden\" value=\""+starttime+"\" />";
					html+="<div class=\"ssname\"><a href='"+jQ("#ctxVal").val()+"/myclip/user.html?"+unameid+"'>"+uname+"</a></div>";
					html+="<div class=\"time\">";
						html+="<span class=\"a\">活动时间：</span>";
						if(iswholeday){
							html+="<span>开始于&nbsp;</span>";
							html+="<b>"+formateDetailTime(starttime)+"</b>";
						}else{
							html+="<b>"+formateDetailTime(starttime)+"</b>";
							html+="<span>&nbsp;至&nbsp;</span>";
							html+="<b>"+formateDetailTime(endtime)+"</b>";
						}
					html+="</div>";
					if(deadlinetime!=null&&eval(deadlinetime)>0){
						html+="<div class=\"time\">";
						html+="<span class=\"a\">截止时间：</span>";
						html+="<b>"+formateDetailTime(eval(deadlinetime))+"</b>";
						html+="</div>";
					}
					html+="<div class=\"topic\">";
						html+="<span class=\"a\">内容：</span>";
						html+="<span class=\"name\">"+title+"</a>";
					html+="</div>";
					if(address!=null&&address.length>0){
						html+="<div class=\"topic\">";
							html+="<span class=\"a\">地址：</span>";
							html+="<span class=\"name\">"+address+"</a>";
						html+="</div>";
					}
					if((content!=null&&content.length>0)||(clipeventpic!=null&&clipeventpic.length>0)){
						html+="<div class=\"txt\">";
						html+="<span class=\"a\">详情：</span>";
						if(content!=null&&content.length>0){
							html+="<span class=\"val\">";
							html+=content;
							html+="</span>";
						}
						if(clipeventpic!=null&&clipeventpic.length>0){
							html+="<div class=\"picture w_clippic bigcursor\">";
								html+="<input type='hidden' value='"+clipeventpic+"'/>";
								html+="<img class='bigcursor' onload='resizeImgCSS(this);' src='"+jQ("#ctxVal").val()+"/clippic/S_"+clipeventpic+"'>";
							html+="</div>";
						}
						html+="</div>";
					}
					html+="<div class=\"opt\">";
					html+=getInterestBtnHTML(isinterest,interestcount);
					html+="<a class='comment' count='"+clipmsgcount+"'>评论("+clipmsgcount+")</a>";
					html+=getFavorBtnHTML(isfavor,favorcount);
					if(iscanfw)
						html+="<a class='forward' onclick='showForwardEvent(this);'>呼朋唤友</a>";
					if(isinterest){
						if(clocktime>0){
							html+="<div class=\"setclock onedit\">";
							html+="<div class=\"middle\">";
							html+="<i class=\"clock\"></i>";
							html+="<span class=\"timedata\">"+formateDetailTime(clocktime)+"</span>";
							html+="<a class=\"cancel\"></a>";
							html+="</div>";
							html+="</div>";
						}else{
							html+="<div class=\"setclock\">";
							html+="<div class=\"middle\">";
							html+="<i class=\"clockoff\"></i>";
							html+="<a class=\"timeset\">设置提醒</a>";
							html+="</div>";
							html+="</div>";
						}
					}
					html+="</div>";
					html+="<div class=\"commentline\" style=\"display: none;\">";
					html+="<input type=\"text\"><button onclick=\"addNewComment(this);\" class=\"commentbtn\"></button>";
					html+="</div>";
					if(iscanfw){
						html+="<div class=\"shareoutzone\">";
						html+="<div class=\"shareoutopt\">";
						html+="<span class=\"shareouttxt\">分享到站外：</span>";
						html+="<a class=\"sinalogo\"></a>";
						html+="<a class=\"weixinlogo\"></a>";
						html+="<a class=\"tqqlogo\"></a>";
						html+="<a class=\"renrenlogo\"></a>";
						html+="<a class=\"kaixin001logo\"></a>";
						html+="<a class=\"doubanlogo\"></a>";
						html+="</div>";
						html+="<div class=\"shareoutcopy\">";
						var tmpurl="http://"+document.domain+jQ("#ctxVal").val()+"/myclip/clip_detail.html?"+shareid;
						html+="<input disabled=\"disabled\" id=\"shareoutcopy_ipt_"+eventid+"\" value='"+tmpurl+"'>";
						html+="<button id=\"shareoutcopy_btn_"+eventid+"\" data-clipboard-target=\"shareoutcopy_ipt_"+eventid+"\"></button>";
						html+="</div>";
						html+="</div>";
					}
					html+="</td>";
					html+="<td class=\"like\">";
						html+="<a class=\"detail\" target='_blank' href='"+jQ("#ctxVal").val()+"/myclip/clip_detail.html?"+shareid+"'></a>";
					html+="</td>";
				html+="</tr>";
			});
			jQ("#clip_content").empty().append(html);
			jQ("#clip_content tr td.avatar").find("a.cancelss").unbind("click").bind("click",cancelSubscribeAtMore);
			jQ("#clip_content tr td.avatar").find("a.ssbtn").unbind("click").bind("click",subscribeAtMore);
			var tdthemeobj=jQ("#clip_content tr td.theme");
			tdthemeobj.find("div.opt div.setclock").find("div.middle a.timeset").unbind("click").bind("click",setclockClipevent);
			tdthemeobj.find("div.opt div.setclock").find("div.middle a.cancel").unbind("click").bind("click",cancelClockevent);
			tdthemeobj.find("div.opt a.interest").unbind("click").bind("click",uninterestClipevent);
			tdthemeobj.find("div.opt a.uninterest").unbind("click").bind("click",interestClipevent);
			tdthemeobj.find("div.opt a.comment").unbind("click").bind("click",showCommentEvent);
			tdthemeobj.find("div.opt a.unfavor").unbind("click").bind("click",favorClipevent);
			tdthemeobj.find("div.opt a.favor").unbind("click").bind("click",unfavorClipevent);
			tdthemeobj.find("div.txt div.picture").unbind("click").bind("click",showClipeventpic);
			
			
			tdthemeobj.find("div.shareoutzone div.shareoutcopy").find("button").each(function(){
				var idstr=jQ(this).prev().attr("id");
				jQ(this).attr("data-clipboard-target",idstr);
				var tempclip=new ZeroClipboard( document.getElementById(jQ(this).attr("id")), {
					moviePath: jQ("#ctxVal").val()+"/js/common/ZeroClipboard.swf",
					positionStyle:"absolute"
				} );
				tempclip.addEventListener("complete",function(){
					copyOptReturnBox(jQ("#"+jQ(this).attr("id")),"复制成功");
				});
			});
			
			initShareOutofSiteATDetail(tdthemeobj);
		}
	});
}

function initShareOutofSiteATDetail(tdthemeobj){
	var sharepart=tdthemeobj.find("div.shareoutzone div.shareoutopt");
	jQ(sharepart).find("a").unbind("click");
	jQ(sharepart).find("a.renrenlogo").bind("click",function(){
		var shareoutoptobj=jQ(this).parent();
		var shareoutzoneobj=shareoutoptobj.parent();
		var shareid=shareoutzoneobj.prevAll("input.shareid").val();
		var title=shareoutzoneobj.prevAll("input.title").val();
		var starttime=eval(shareoutzoneobj.prevAll("input.starttime").val());
		var day=new Date();
		day.setTime(starttime);
		var startstr=day.pattern("yyyy年MM月dd日");
		var txtobj=shareoutzoneobj.prevAll("div.txt");
		var url="http://"+document.domain+jQ("#ctxVal").val()+"/myclip/clip_detail.html?"+shareid;
		var img="";
		if(txtobj.length>0){
			var pictureobj=txtobj.find("div.picture");
			if(pictureobj.length>0){
				var clipeventpic=pictureobj.find("input").val();
				img="http://"+document.domain+jQ("#ctxVal").val()+"/clippic/"+clipeventpic;
			}
		}
		var rrShareParam = {
			resourceUrl : url,	//分享的资源Url
			srcUrl :url,	//分享的资源来源Url,默认为header中的Referer,如果分享失败可以调整此值为resourceUrl试试
			pic : img,		//分享的主题图片Url
			title : '档期分享：'+startstr+'  '+title,		//分享的标题
			description : '更多详情请点击'	//分享的详细描述
		};
		var temp = [];
		for( var p in rrShareParam ){
			temp.push(p + '=' + encodeURIComponent( rrShareParam[p] || '' ) )
		}
		
		
		window.open(
		'http://widget.renren.com/dialog/share?' + temp.join('&'),
		'_blank'); 
	});
	
	jQ(sharepart).find("a.kaixin001logo").bind("click",function(){
		var shareoutoptobj=jQ(this).parent();
		var shareoutzoneobj=shareoutoptobj.parent();
		var shareid=shareoutzoneobj.prevAll("input.shareid").val();
		var title=shareoutzoneobj.prevAll("input.title").val();
		var starttime=eval(shareoutzoneobj.prevAll("input.starttime").val());
		var day=new Date();
		day.setTime(starttime);
		var startstr=day.pattern("yyyy年MM月dd日");
		var url="http://"+document.domain+jQ("#ctxVal").val()+"/myclip/clip_detail.html?"+shareid;
		window.open(
		'http://www.kaixin001.com/repaste/share.php?rurl='+url
		+'&rtitle=档期分享'
		+'&rcontent='+startstr+'  '+title+'    '+'更多详情请点击',
		'_blank',
		'height=500,width=700,top=200,left=410,toolbar=no,menubar=no,scrollbars=no,resizable=no,location=no, status=no');
		
	});
	
	jQ(sharepart).find("a.sinalogo").bind("click",function(){
		var shareoutoptobj=jQ(this).parent();
		var shareoutzoneobj=shareoutoptobj.parent();
		var shareid=shareoutzoneobj.prevAll("input.shareid").val();
		var title=shareoutzoneobj.prevAll("input.title").val();
		var starttime=eval(shareoutzoneobj.prevAll("input.starttime").val());
		var day=new Date();
		day.setTime(starttime);
		var startstr=day.pattern("yyyy年MM月dd日");
		var txtobj=shareoutzoneobj.prevAll("div.txt");
		var url="http://"+document.domain+jQ("#ctxVal").val()+"/myclip/clip_detail.html?"+shareid;
		var img="";
		if(txtobj.length>0){
			var pictureobj=txtobj.find("div.picture");
			if(pictureobj.length>0){
				var clipeventpic=pictureobj.find("input").val();
				img="http://"+document.domain+jQ("#ctxVal").val()+"/clippic/"+clipeventpic;
			}
		}
		var param = {
		    url:url,
		    type:'3',
		    title:'档期分享：'+startstr+'  '+title+'    '+'更多详情请点击',
		    pic:img,
		    ralateUid:'2618696840',
			language:'zh_cn',
		    rnd:new Date().valueOf()
		  }
		var temp = [];
		for( var p in param ){
			temp.push(p + '=' + encodeURIComponent( param[p] || '' ) )
		}
		window.open(
				'http://service.weibo.com/share/share.php?' + temp.join('&') ,
				'_blank',
		'height=520,width=607,top=150,left=410,toolbar=no,menubar=no,scrollbars=no,resizable=no,location=no, status=no');
	});
	jQ(sharepart).find("a.doubanlogo").bind("click",function(){
		var shareoutoptobj=jQ(this).parent();
		var shareoutzoneobj=shareoutoptobj.parent();
		var shareid=shareoutzoneobj.prevAll("input.shareid").val();
		var title=shareoutzoneobj.prevAll("input.title").val();
		var starttime=eval(shareoutzoneobj.prevAll("input.starttime").val());
		var day=new Date();
		day.setTime(starttime);
		var startstr=day.pattern("yyyy年MM月dd日");
		var url="http://"+document.domain+jQ("#ctxVal").val()+"/myclip/clip_detail.html?"+shareid;
		window.open(
		'http://www.douban.com/recommend/?url='+url
		+'&title=档期分享'+
		+'&comment='+startstr+'  '+title+'    '+'更多详情请点击',
		'_blank',
		'height=370,width=505,top=300,left=450,toolbar=no,menubar=no,scrollbars=no,resizable=no,location=no, status=no');
	});
	jQ(sharepart).find("a.weixinlogo").bind("click",function(){
		var shareoutoptobj=jQ(this).parent();
		var shareoutzoneobj=shareoutoptobj.parent();
		var shareid=shareoutzoneobj.prevAll("input.shareid").val();
//		var title=shareoutzoneobj.prevAll("input.title").val();
//		var starttime=eval(shareoutzoneobj.prevAll("input.starttime").val());
//		var day=new Date();
//		day.setTime(starttime);
//		var startstr=day.pattern("yyyy年MM月dd日");
//		var url="http://"+document.domain+jQ("#ctxVal").val()+"/myclip/clip_detail.html?"+shareid;
//		var txtobj=shareoutzoneobj.prevAll("div.txt");
//		var img="";
//		if(txtobj.length>0){
//			var pictureobj=txtobj.find("div.picture");
//			if(pictureobj.length>0){
//				var clipeventpic=pictureobj.find("input").val();
//				img="http://"+document.domain+jQ("#ctxVal").val()+"/clippic/"+clipeventpic;
//			}
//		}
		init2weixinbox(shareid);
	});
	jQ(sharepart).find("a.tqqlogo").bind("click",function(){
		var shareoutoptobj=jQ(this).parent();
		var shareoutzoneobj=shareoutoptobj.parent();
		var shareid=shareoutzoneobj.prevAll("input.shareid").val();
		var title=shareoutzoneobj.prevAll("input.title").val();
		var starttime=eval(shareoutzoneobj.prevAll("input.starttime").val());
		var day=new Date();
		day.setTime(starttime);
		var startstr=day.pattern("yyyy年MM月dd日");
		var txtobj=shareoutzoneobj.prevAll("div.txt");
		var url="http://"+document.domain+jQ("#ctxVal").val()+"/myclip/clip_detail.html?"+shareid;
		var img="";
		if(txtobj.length>0){
			var pictureobj=txtobj.find("div.picture");
			if(pictureobj.length>0){
				var clipeventpic=pictureobj.find("input").val();
				img="http://"+document.domain+jQ("#ctxVal").val()+"/clippic/"+clipeventpic;
			}
		}
		var param = {
		    url:url,
		    appkey:'',
		    title:'档期分享：'+startstr+'  '+title+'    '+'更多详情请点击',
		    pic:img,
		    site:'www.clip24.cn'
		};
		var temp = [];
		for( var p in param ){
			temp.push(p + '=' + encodeURIComponent( param[p] || '' ) )
		}
		var _u = 'http://v.t.qq.com/share/share.php?'+ temp.join('&');
		window.open( _u,'转播到腾讯微博', 'width=700, height=680, top=0, left=0, toolbar=no, menubar=no, scrollbars=no, location=yes, resizable=no, status=no' );
	});
}

function initPaging(currentpage,pagecount){
	jQ("#pagingpart").empty();
	if(pagecount<=1){
		return;
	}else{
		var pagemin=currentpage-2;
		var pagemax=currentpage+2;
		if(pagemin<0){
			pagemin=0;
		}
		if(pagemax>pagecount-1){
			pagemax=pagecount-1;
		}
		var html="<div class=\"pagecount\" >共有"+pagecount+"页</div>";
		html+="<div class=\"page\">";
		html+="<a page='first'><span >&lt;&lt;</span></a>";
		for(var i=pagemin;i<=pagemax;i++){
			if(i==currentpage){
				html+="<b ><span>"+(i+1)+"</span></b>";
			}else
				html+="<a page='"+i+"'><span>"+(i+1)+"</span></a>";
		}
		html+="<a page='last'><span >&gt;&gt;</span></a>";
		html+="</div>";
		jQ("#pagingpart").append(html);
		jQ("#pagingpart").find("div.page").find("a").unbind("click").bind("click",function(){
			var page=jQ(this).attr("page");
			var currentpage=0;
			if(page=="first"){
				currentpage=0;
			}else if(page=="last"){
				currentpage=pagecount-1;
			}else{
				currentpage=eval(page);
			}
			jQ("#subscribetabs").data("currentpage",currentpage);
			jQ("#subscribetabs").trigger("load");
			
		});
	}
}

function showForwardEvent(obj){
	var btnline=jQ(obj).parent();
	if(btnline.nextAll("div.zonecontent").length>0){
		if(btnline.nextAll("div.zonecontent").css("display")=="none"){
			btnline.nextAll("div.zonecontent").show();
		}else{
			btnline.nextAll("div.zonecontent").hide();
		}
	}else{
		btnline.after(jQ("#forwardsharepart").clone().html());
	}
	
}

function cancelshareclick(obj){
	jQ(obj).parent().parent().hide();
}

function showClipeventpic(event){
	var target=jQ(event.currentTarget);
	var clipeventpic=target.find("input").val();
	if(target.hasClass("bigcursor")){
		//放大
		target.removeClass("bigcursor").addClass("smallcursor");
		target.find("img").removeClass().addClass("smallcursor");
		target.find("img").hide();
		target.find("img").attr("src",jQ("#ctxVal").val()+"/clippic/"+clipeventpic).attr("width",480);
	}else{
		//缩小
		target.removeClass("smallcursor").addClass("bigcursor");
		target.find("img").removeClass().addClass("bigcursor");
		target.find("img").hide();
		target.find("img").attr("src",jQ("#ctxVal").val()+"/clippic/S_"+clipeventpic).removeAttr("width");
	}
	
}

function subscribeAtMore(event){
	var thisobj=jQ(event.currentTarget);
	var uid=eval(thisobj.attr("uid"));
	jQ.ajax({
		type:"POST",
		url: "contactAjax!subscribeCC.action",
		data:{
			uid:uid
		},
		success:function(data){
			var dataObj=eval("("+data+")");//转换为json对象
			if(dataObj.result){
				jQ("#clip_content tr td.avatar").each(function(){
					var btnobj=jQ(this).find("a.ssbtn");
					if(eval(btnobj.attr("uid"))==uid){
						btnobj.removeClass().addClass("cancelss").unbind("click").bind("click",cancelSubscribeAtMore);
					}
				});
			}
		}
	});
}

function cancelSubscribeAtMore(event){
	var thisobj=jQ(event.currentTarget);
	var name=thisobj.prev().attr("title");
	var uid=eval(thisobj.attr("uid"));
	invitingOptReturnBox(jQ(this),"确定不再订阅 <font>"+name+"</font> ?");
	jQ("#msg_box_opt a.confirm").unbind("click").bind("click",function(){
		jQ.ajax({
			type:"POST",
			url: "contactAjax!unsubscribeCC.action",
			data:{
				uid:uid
			},
			success:function(data){
				var dataObj=eval("("+data+")");//转换为json对象
				if(dataObj.result){
					jQ("#msg_box").find("div.msg_note").animate({top: 200+'px'},500,function(){
						jQ("#msg_box").hide();
						jQ("#clip_content tr td.avatar").each(function(){
							var btnobj=jQ(this).find("a.cancelss");
							if(eval(btnobj.attr("uid"))==uid){
								btnobj.removeClass().addClass("ssbtn").unbind("click").bind("click",subscribeAtMore);
							}
						});
					});
					
				}
			}
		});
	});
	jQ("#msg_box_opt a.cancel").unbind("click").bind("click",function(){
		jQ("#msg_box").find("div.msg_note").animate({top: 200+'px'},500,function(){jQ("#msg_box").hide();});
	});
}

function cancelSubscribe(event){
	var thisobj=jQ(event.currentTarget);
	
	var name=thisobj.prev().attr("title");
	
	var uid=eval(thisobj.attr("uid"));
	invitingOptReturnBox(jQ(this),"确定不再订阅 <font>"+name+"</font> ?");
	jQ("#msg_box_opt a.confirm").unbind("click").bind("click",function(){
		jQ.ajax({
			type:"POST",
			url: "contactAjax!unsubscribeCC.action",
			data:{
				uid:uid
			},
			success:function(data){
				var dataObj=eval("("+data+")");//转换为json对象
				if(dataObj.result){
					jQ("#msg_box").find("div.msg_note").animate({top: 200+'px'},500,function(){
						jQ("#msg_box").hide();
						jQ("#subscribetabs").data("currentpage",0);
						loadMySubscribes();
					});
					
				}
			}
		});
	});
	jQ("#msg_box_opt a.cancel").unbind("click").bind("click",function(){
		jQ("#msg_box").find("div.msg_note").animate({top: 200+'px'},500,function(){jQ("#msg_box").hide();});
	});
}

function setclockClipevent(event){
	var tar=jQ(event.currentTarget);
	var setclockobj=tar.parent().parent();
	var tdobj=setclockobj.parent().parent();
	var trobj=tdobj.parent();
	tar.prev().removeClass().addClass("clock");
	tar.parent().parent().addClass("onedit");
	tar.hide();
	var html="";
	html+="<input class=\"date\"/>";
	html+="<input class=\"time hour\" value=\"0\"/>";
	html+="<span class=\"time\">时</span>";
	html+="<input class=\"time min\" value=\"0\"/>";
	html+="<span class=\"time\">分</span>";
	html+="<a class=\"confirm\"></a>";
	html+="<a class=\"cancel\"></a>";
	tar.after(html);
	tar.nextAll("input.date").data("eventid",trobj.attr("eventid"));
	tar.nextAll("input.date").datepicker({
		yearRange : '1950:2020',
		dateFormat:'yy-mm-dd',
		changeMonth:true,
		changeYear:true,
		beforeShow: function(i,e){  
		var z = jQuery(i).closest(".ui-dialog").css("z-index") + 4;  
		e.dpDiv.css('z-index', z);  
		e.dpDiv.css('font', "14px \"Trebuchet MS\", sans-serif");
		}
    });
	tar.nextAll("input.hour").unbind("blur").bind("blur",hourinput);
	tar.nextAll("input.min").unbind("blur").bind("blur",mininput);
	tar.nextAll("a.cancel").unbind("click").bind("click",function(){
		var clockobj=jQ(this).prevAll("i.clock");
		jQ(this).parent().parent().removeClass("onedit");
		clockobj.removeClass("clock").addClass("clockoff");
		clockobj.nextAll().remove();
		clockobj.after("<a class=\"timeset\">设置提醒</a>");
		clockobj.nextAll("a.timeset").unbind("click").bind("click",setclockClipevent);
	});
	tar.nextAll("a.confirm").unbind("click").bind("click",function(){
		var alertdate=jQ(this).prevAll("input.date").datepicker( "getDate" );
		if(alertdate==null||alertdate.length<=0){
			clip_tips("请选择提醒日期。");
			return false;
		}
		var alerthour=getHourValue(jQ(this).prevAll("input.hour").val());
		if(alerthour==null){
			clip_tips("请选择正确的小时数。");
			return false;
		}
		var alertmin=getMiniuteValue(jQ(this).prevAll("input.min").val());
		if(alertmin==null){
			clip_tips("请选择正确的分钟数。");
			return false;
		}
		alertdate.setHours(alerthour);
		alertdate.setMinutes(alertmin);
		var alertlong=alertdate.getTime();
		var nowdate=new Date();
		if(alertlong<nowdate){
			clip_tips("提醒的时间应该是将来的时间。");
			return false;
		}
		var clockobj=jQ(this).prevAll("i.clock");
		var eventid=jQ(this).prevAll("input.date").data("eventid");
		jQ.ajax({
			type: "POST",
			url:"eventAjax!addEventClock.action",
			data:{
				eventid:eval(eventid),
				alerttime:alertlong,
				mobilenotice:0
			},
			success:function(data){
				if(data!=null){
					var dataObj=eval("("+data+")");//转换为json对象
					if(dataObj.result){
						var temphtml="";
						temphtml+="<span class=\"timedata\">"+formateDetailTime(alertlong)+"</span>";
						temphtml+="<a class=\"cancel\"></a>";
						clockobj.nextAll().remove();
						clockobj.after(temphtml);
						clockobj.nextAll("a.cancel").unbind("click").bind("click",cancelClockevent);
					}else{
						
					}
				}
			}
		});
	});
	tar.remove();
}

function getHourValue(hour){
	if(isNumber(hour)){
		var tmp=eval(hour);
		if(tmp>=0&&tmp<=23){
			return tmp;
		}else
			return null;
	}else
		return null;
}

function getMiniuteValue(min){
	if(isNumber(min)){
		var tmp=eval(min);
		if(tmp>=0&&tmp<=59){
			return tmp;
		}else
			return null;
	}else
		return null;
}

function cancelClockevent(event){
	var tar=jQ(event.currentTarget);
	var setclockobj=tar.parent().parent();
	var tdobj=setclockobj.parent().parent();
	var trobj=tdobj.parent();
	var eventid=trobj.attr("eventid");
	var clockobj=tar.prevAll("i.clock");
	jQ.ajax({
		type: "POST",
		url:"eventAjax!cancelClock.action",
		data:{
			eventid:eval(eventid)
		},
		success:function(data){
			if(data.result){
				var temphtml="";
				temphtml+="<a class=\"timeset\">设置提醒</a>";
				clockobj.parent().parent().removeClass("onedit");
				clockobj.nextAll().remove();
				clockobj.after(temphtml);
				clockobj.removeClass("clock").addClass("clockoff");
				clockobj.next().unbind("click").bind("click",setclockClipevent);
			}else{
				
			}
		}
	});
}

function uninterestClipevent(event){

	var tar=jQ(event.currentTarget);
	var tdobj=tar.parent().parent();
	var trobj=tdobj.parent();
	var eventid=trobj.attr("eventid");

	jQ.ajax({
		type: "POST",
		url:"shareAjax!uninterestShareEvent.action",
		data:{
			eventid:eval(eventid)
		},
		success:function(data){
			if(data!=null){
				var dataObj=eval("("+data+")");//转换为json对象
				if(dataObj.result){
					copyOptReturnBox(tar,"档期从您的日历中移除");
					tar.removeClass().addClass("uninterest").attr("title","表示对该档期的感兴趣");
					tar.unbind("click").bind("click",interestClipevent);
					tar.parent().find("div.setclock").remove();
					var interestcount=eval(tar.attr("count"));
					interestcount--;
					var interestcountstr=interestcount>99999?"99999+":""+interestcount;
					tar.attr("count",interestcount);
					tar.text("感兴趣("+interestcountstr+")");
				}else{
					clip_tips(dataObj.msg);
//					window.location.reload();
				}
			}
		}
	});

}

function interestClipevent(event){

	var tar=jQ(event.currentTarget);
	var tdobj=tar.parent().parent();
	var trobj=tdobj.parent();
	var eventid=trobj.attr("eventid");
	jQ.ajax({
		type: "POST",
		url:"shareAjax!interestShareEvent.action",
		data:{
			eventid:eval(eventid)
		},
		success:function(data){
			if(data!=null){
				var dataObj=eval("("+data+")");//转换为json对象
				if(dataObj.result){
					copyOptReturnBox(tar,"档期存至您的日历");
					var interestcount=eval(tar.attr("count"));
					interestcount++;
					tar.attr("count",interestcount);
					var interestcountstr=interestcount>99999?"99999+":""+interestcount;
					tar.text("取消感兴趣("+interestcountstr+")");
					tar.removeClass().addClass("interest").attr("title","取消对该档期的感兴趣");
					tar.unbind("click").bind("click",uninterestClipevent);
					var temphtml="";
					temphtml+="<div class=\"setclock\">";
					temphtml+="<div class=\"middle\">";
					temphtml+="<i class=\"clockoff\"></i>";
					temphtml+="<a class=\"timeset\">设置提醒</a>";
					temphtml+="</div>";
					temphtml+="</div>";
					tar.parent().find("a:last").after(temphtml);
					tar.parent().find("div.setclock").find("div.middle a.timeset").unbind("click").bind("click",setclockClipevent);

				}else{
					alert(dataObj.msg);
//					window.location.reload();
				}
			}
		}
	});

}

function showCommentEvent(event){
	var tar=jQ(event.currentTarget);
	tar.parent().nextAll("div.commentline").toggle();
}

function addNewComment(obj){
	var commentlineobj=jQ(obj).parent();
	var tdobj=commentlineobj.parent();
	var trobj=tdobj.parent();
	var eventid=trobj.attr("eventid");
	var replyobj=jQ(obj).prev();
	var content=jQ.trim(replyobj.val());
	if(content==null||content.length==0){
		clip_tips("回复内容不能为空。");
	}else{
		if(content.length>255)
			clip_tips("回复内容不能超过255个字符。"); 
	}
	jQ.ajax({
		type: "POST",
		url:"eventAjax!addreply.action",
		data:{
			eventid:eval(eventid),
			content:content
		},
		success:function(data){
			if(data.result){
				commentlineobj.toggle();
				replyobj.val("");
				
				var optobj=commentlineobj.prev("div.opt");
				var commentbtn=optobj.find("a.comment");
				var commentcount=commentbtn.attr("count");
				commentcount++;
				var commentcountstr=commentcount>99999?"99999+":""+commentcount;
				commentbtn.text("评论("+commentcountstr+")");
			}else{
				
			}
		}
	});
}

function favorClipevent(event){
	var btnobj=jQ(event.currentTarget);
	var tdobj=btnobj.parent().parent();
	var trobj=tdobj.parent();
	var eventid=trobj.attr("eventid");
	jQ.ajax({
		type: "POST",
		url:"shareAjax!favorShareEvent.action",
		data:{
			eventid:eval(eventid)
		},
		success:function(data){
			if(data!=null){
				var dataObj=eval("("+data+")");//转换为json对象
				if(dataObj.result){
					var favorcount=btnobj.attr("count");
					favorcount++;
					btnobj.data("count",favorcount);
					var favorcountstr=favorcount>99999?"99999+":""+favorcount;
					btnobj.text("取消喜欢("+favorcountstr+")");
					btnobj.removeClass().addClass("favor").attr("title","取消喜欢该档期");
					btnobj.unbind("click").bind("click",unfavorClipevent);
				}else{
					alert(dataObj.msg);
					window.location.reload();
				}
			}
		}
	});
}

function unfavorClipevent(event){
	var btnobj=jQ(event.currentTarget);
	var tdobj=btnobj.parent().parent();
	var trobj=tdobj.parent();
	var eventid=trobj.attr("eventid");
	jQ.ajax({
		type: "POST",
		url:"shareAjax!unfavorShareEvent.action",
		data:{
			eventid:eval(eventid)
		},
		success:function(data){
			if(data!=null){
				var dataObj=eval("("+data+")");//转换为json对象
				if(dataObj.result){
					var favorcount=btnobj.attr("count");
					favorcount--;
					btnobj.data("count",favorcount);
					var favorcountstr=favorcount>99999?"99999+":""+favorcount;
					btnobj.text("喜欢("+favorcountstr+")");
					btnobj.removeClass().addClass("unfavor").attr("title","喜欢该档期");
					btnobj.unbind("click").bind("click",favorClipevent);
				}else{
					alert(dataObj.msg);
					window.location.reload();
				}
			}
		}
	});
}


function invitingOptReturnBox(obj,content){
	var obj_box = jQ(obj);
	var obj_offset = obj_box.offset();
	var msg_box = jQ("#msg_box");
	jQ("#msg_box_content").empty().append(content);
	var _top = obj_offset.top - msg_box.outerHeight() +10;
	var _left = obj_offset.left - msg_box.outerHeight()/2;
	msg_box.css({"top":_top+"px","left":_left+"px"}).show();
	msg_box.find("div.msg_note").animate({top: 20+'px'}, 500,function(){

	});
}

function prevDateClick(){
	var currentdate=jQ("#subscribetabs").data("currentdate");
	currentdate.setDate(currentdate.getDate()-1);
	jQ("#subscribetabs").data("currentdate",currentdate);
	jQ("#subscribetabs").data("currentpage",0);
	loadMySubscribes();
}

function nextDateClick(){
	var currentdate=jQ("#subscribetabs").data("currentdate");
	currentdate.setDate(currentdate.getDate()+1);
	jQ("#subscribetabs").data("currentdate",currentdate);
	jQ("#subscribetabs").data("currentpage",0);
	loadMySubscribes();
}



function formateDetailTime(daytime){
	var temp=new Date();
	temp.setTime(eval(daytime));
	return temp.pattern("yyyy-MM-dd HH:mm");
}

function formateTime(daytime){
	var temp=new Date();
	temp.setTime(eval(daytime));
	return temp.pattern("yyyy-MM-dd");
}

function resizeImgCSS(img){
	/*var LastestWIDTH=190;
	var LastestHEIGHT=150;*/
    if(typeof(img)!='object')
        img=document.getElementById(img);
    if(img==null)
        return;
    var image=document.createElement("img");
    image.onload=function (){
        var width=this.width;
        var height=this.height;
        if(width<90&&jQ(img).parent().hasClass("bigcursor")){
        	if(jQ(img).parent().hasClass("w_clippic"))
        		jQ(img).parent().removeClass("w_clippic");
        }else{
        	if(!jQ(img).parent().hasClass("w_clippic"))
        		jQ(img).parent().addClass("w_clippic");
        }
        jQ(img).fadeIn();
    };
    image.src=img.src;
}

function initContacts(){
	jQ.ajax({
		type:"POST",
		url: "contactAjax!loadContactAll.action",
		success:function(data){
			if(data!=null){
				add_clipCreateContentHtml(data);
				jQ("#addclipcontactmbtab span").click(function(){
					if(jQ(this).hasClass("onit"))
						return;
					else{
						var conid=jQ("#addclipcontactmbtab span.onit").attr("conid");
						jQ("#"+conid).hide();
						jQ("#addclipcontactmbtab span.onit").removeClass().addClass("nor");
						var conshowid=jQ(this).attr("conid");
						jQ("#"+conshowid).show();
						jQ(this).removeClass().addClass("onit");
					}
				});
			}
		}
	});
}

function add_clipCreateContentHtml(data){
	var typelength=jQ(data).find("Contact").length;
	var html="";
	if(typelength==0){
		html="<dt ><a class='dis_sel'/>";
		html+="<a class='tipexpand'>所有联系人</a><span>[0]</span></dt>";
	}else{
		html="<dt><a class='no_sel'/>";
		html+="<b onclick='add_clipOpenClose2(this)' class='tipexpand'>所有联系人</b><span>["+typelength+"]</span></dt>"
		jQ(data).find("Contact").each(function(i,d){
			var uid=jQ(d).find("uid").text();
			html+="<dd class='contactelement' uid='uid_"+uid+"'>";
			html+="<div class='check'><a class='no_sel' uid='"+uid+"' /><input type='hidden' value='"+uid+"' class='uid'/><input type='hidden' value='"+jQ(d).find("hasmobile").text()+"' class='hasmobile'/></div>";
			html+="<a class='logo' href=\""+jQ("#ctxVal").val()+"/myclip/user.html?"+uid+"\"><img src=\""+jQ(d).find("logo").text()+"\"/></a>";
			html+="<div class='name'>"+jQ(d).find("name").text()+"</div>";
			html+="<div class='email_add'>"+jQ(d).find("email").text()+"</div>";
			html+="</dd>";
		});
	}
	jQ("#contact_friend").empty().append(html);
	var grouphtml="";
	var grouplength=jQ(data).find("ContactGroup").length;
	if(grouplength==0){
		grouphtml="<li ><span class='info'>快去管理您的<a href='"+jQ("#ctxVal").val()+"/contact/group.html"+"'>群组</a>吧</span></li>";
	}else{
		jQ( "ContactGroup ", data ).each(function(){
			var groupname=jQ("groupname", this).text();
			var groupid=jQ(this).attr("id");
			var membercount=jQ("membercount", this).text();
			var countstr;
			if(membercount>99){
				countstr=membercount+"+";
			}else{
				countstr=membercount;
			}
			var groupcontactlength=jQ(this).find("groupContact").length; 
			if(groupcontactlength==0){
				grouphtml+="<li><dt><a class=\"dis_sel\"></a>";
			}else{
				grouphtml+="<li groupid="+groupid+"><dt><a class=\"no_sel\" ></a>";
			}
			grouphtml+="<b class=\"tipexpand close\" >"+groupname+"</b><span>["+groupcontactlength+"]</span></dt>";
			jQ(this).find("groupContact").each(function(){
				var contactid=jQ(this).attr("id");
				var contactobj=jQ(data).find("Contact[id="+contactid+"]");
				var uid=contactobj.find("uid").text();
				grouphtml+="<dd class='contactelement' uid='uid_"+uid+"' style='display:none;'>";
				grouphtml+="<div class='check'><a class='no_sel' uid='"+uid+"'/><input type='hidden' value='"+uid+"' class='uid'/><input type='hidden' value='"+contactobj.find("hasmobile").text()+"' class='hasmobile'/></div>";
				grouphtml+="<a class='logo' href=\""+jQ("#ctxVal").val()+"/myclip/user.html?"+uid+"\"><img src=\""+contactobj.find("logo").text()+"\"/></a>";
				grouphtml+="<div class='name'>"+contactobj.find("name").text()+"</div>";
				grouphtml+="<div class='email_add'>"+contactobj.find("email").text()+"</div>";
				grouphtml+="</dd>";
			});
			grouphtml+="</li>";
		});
	}
	jQ("#inv_congroup").empty().append(grouphtml);
	var btnline=jQ("#chosen_friend").next("div.btnline");
	btnline.find("button.cancel").unbind("click").bind("click",close_Addclipcontactlist_Dialog);
}

function close_Addclipcontactlist_Dialog(){
	jQ("#addclipcontactlist").hide();
	jQ("#chosen_friend").empty();
	jQ("#chosen_friend").parent().hide();
}

function showForwardContactDetailTip(obj){
	if(jQ("#addclipcontactlist").css("display")=="none"){
		var btnobj=jQ(obj);
		var zonecontentobj=btnobj.parent().parent();
		var tdobj=zonecontentobj.parent();
		var trobj=tdobj.parent();
		var eventid=eval(trobj.attr("eventid"));
		jQ("#addclipcontactlist").data("eventid",eventid);
//		var chooseobj=.parent();
//		var zonecontentid=chooseobj.parent().attr("id");
		jQ("#addclipcontactmbtab span:first").removeClass().addClass("onit").show();
		jQ("#addclipcontactmbtab span:last").removeClass().addClass("nor");
		jQ("#contact").show();
		jQ("#inv_congroup li dt b.tipexpand").removeClass("hidebg");
		jQ("#inv_congroup li dt b.tipexpand").unbind("click").bind("click",add_clipOpenClose2);
		
		jQ("#contact_friend dt a:first").attr("class","no_sel");
		jQ("#inv_congroup").hide();
		jQ("#inv_congroup li dt a[class!='dis_sel']").removeClass().addClass("no_sel");
		jQ("#inv_congroup li dd div.check  a").attr("class","no_sel");
		jQ("#contact_friend dd div.check  a").attr("class","no_sel");
		
		var box = jQ(obj).offset();
		jQ("html,body").animate({scrollTop:box.top},1000);
		jQ("#addclipcontactlist").css({"top":box.top-40,"left":box.left+30}).show();
		jQ("#addclipcontactlist").show();
																/***1***/
		jQ("#contact_friend dt a").unbind("click").bind("click",selAllsynchronizecontactlistOnContact);
																			/***2***/
		jQ("#contact_friend dd a").unbind("click").bind("click",synchronizecontactlistOnContact);
																/***3***/
		jQ("#inv_congroup li dt a").unbind("click").bind("click",selAllsynchronizecontactlistOnGroup);
																						/***4***/
		jQ("#inv_congroup li dd.contactelement a").unbind("click").bind("click",synchronizecontactlistOnGroup);
		
		var btnline=jQ("#chosen_friend").next("div.btnline");
		btnline.find("button.confirm").unbind("click").bind("click",function(){
			
		

			var html="";
			jQ("#chosen_friend li").each(function(){
				var divobj=jQ(this).find("div");
				var url=divobj.attr("style");
				var uid=jQ(this).attr("uid");
				var name=jQ(this).find("span").attr("title");
				html+="<li style=\""+url+"\" title='"+name+"' uid='"+uid+"'>";
			});
			jQ("#forward_invite_list").empty().append(html);
			jQ("#forward_invite_dateinput").datepicker("destroy");
			jQ("#forward_invite_dateinput").val("");
			jQ("#forward_invite_dateinput").datepicker({
				yearRange : '1950:2020',
				dateFormat:'yy-mm-dd',
				changeMonth:true,
				changeYear:true,
				detailtime:false,
				beforeShow: function(i,e){  
					var z = jQuery(i).closest(".ui-dialog").css("z-index") + 4;  
					e.dpDiv.css('z-index', z);
					e.dpDiv.css('font', "14px \"Trebuchet MS\", sans-serif");
				}
		    });
			jQ("#forward_invitetime_wrap").show();
			
			jQ("#forward_invitetime_fw").unbind("click").bind("click",forwardShareEventWithoutTime);
			jQ("#forward_invitetime_confirm").unbind("click").bind("click",forwardShareEventWithTime);
			jQ("#forward_invitetime_close").unbind("click").bind("click",function(){
				jQ("#forward_invitetime_wrap").hide();
				jQ("#forward_invite_dateinput").datepicker("destroy");
				jQ("#forward_invitetime_close").unbind("click");
				jQ("#forward_invitetime_confirm").unbind("click");
				jQ("#forward_invite_list").empty();
				jQ("#forward_invitetime_confirm").removeData("liid");
				
			});
			
		});
	}else{
		jQ("#addclipcontactlist").hide();
		jQ("#addclipcontactlist").removeData("eventid");
	}
	
}

function forwardShareEventWithoutTime(event){
	jQ("#loadingui").show();
	jQ("#chosen_friend").parent().hide();
	var eventid=jQ("#addclipcontactlist").data("eventid");
	var addcontactlist="";
	var addcontactmobilelist="";
	jQ("#chosen_friend").find("li").each(function(){
		var ulstr=jQ(this).attr("uid");
		var ularr=ulstr.split("_");
		if(addcontactlist.length<=0){
			addcontactlist+=ularr[1];
		}else{
			addcontactlist+=","+ularr[1];
		}
		if(jQ(this).find("i.onit").length>0){
			if(addcontactmobilelist.length<=0){
				addcontactmobilelist+=ularr[1];
			}else{
				addcontactmobilelist+=","+ularr[1];
			}
		}
	});
	jQ.ajax({
		type:"POST",
		url: "shareAjax!forwardShareEvent.action",
		data:{
			eventid:eventid,
			share2userlist:addcontactlist,
			mlist:addcontactmobilelist
		},
		success:function(data){
			
			var dataObj=data;//转换为json对象
			if(dataObj.result){
				close_Addclipcontactlist_Dialog();
				jQ("#forward_invitetime_wrap").hide();
				jQ("#forward_invite_list").empty();
				jQ("#loadingui").hide();
				var shareid=dataObj.shareid;
				var title=dataObj.title;
				var starttime=dataObj.starttime;
				var trobj=jQ("tr[eventid="+eventid+"]");
				var tdobj=trobj.find("td.theme");
				var zonecontentobj=tdobj.find("div.zonecontent");
				var imgobj=dataObj.clipeventpic;
				var visiturl=jQ("#ctxVal").val()+"/myclip/clip_detail.html?"+shareid;
				jQ("#add_return a.close").unbind("click").bind("click",function(){
					window.open(visiturl);
					zonecontentobj.hide();
					jQ("#add_return_wrap").hide();
				});
				jQ("#add_return div.btnline button").unbind("click").bind("click",function(){
					window.open(visiturl);
					zonecontentobj.hide();
					jQ("#add_return_wrap").hide();
				});
				jQ("#add_return_vcode_ipt").bind("focus",function(){
					if(!jQ(this).hasClass("onfocus")){
						jQ(this).val("");
						jQ(this).addClass("onfocus");
					}
				});
				jQ("#add_return_vcode_ipt").bind("blur",function(){
					if(jQ.trim(jQ(this).val()).length==0){
						jQ(this).val("4位数字");
						jQ(this).removeClass("onfocus");
					}
				});
				jQ("#add_return_vcode_ipt").data("eventid",dataObj.eventid);
				jQ("#add_return_vcode").show();
				jQ("#add_return_visit_url").val("http://"+document.domain+visiturl);
				initForwardClipboardOpt();
				initShareOutofSite(shareid,title,starttime,imgobj);
				jQ("#add_return_wrap").show();
				//跳转至详情页面
			}else{
				clip_tips(dataObj.msg);
			}
			
		}
	});
}

function forwardShareEventWithTime(event){
	var selectedDate=jQ("#forward_invite_dateinput").datepicker("getDate");
	if(selectedDate==null){
		jQ("#forward_invite_info").empty().append("请选择邀请好友参与的时间");
		return;
	}else
		jQ("#forward_invite_info").empty();
	var addcontactlist="";
	var addcontactmobilelist="";
	jQ("#forward_invite_list").find("li").each(function(){
		var ulstr=jQ(this).attr("uid");
		var ularr=ulstr.split("_");
		if(addcontactlist.length<=0){
			addcontactlist+=ularr[1];
		}else{
			addcontactlist+=","+ularr[1];
		}
	});
	var hour=eval(jQ("#forward_invite_hour").val());
	var min=eval(jQ("#forward_invite_min").val());
	selectedDate.setHours(hour);
	selectedDate.setMinutes(min);
	var invitetime=selectedDate.getTime();
	var eventid=jQ("#addclipcontactlist").data("eventid");
	jQ.ajax({
		type:"POST",
		url: "shareAjax!forwardShareEvent.action",
		data:{
			eventid:eventid,
			share2userlist:addcontactlist,
			mlist:addcontactmobilelist,
			invitetime:invitetime
		},
		success:function(data){
			
			var dataObj=data;//转换为json对象
			if(dataObj.result){
				close_Addclipcontactlist_Dialog();
				jQ("#forward_invitetime_wrap").hide();
				jQ("#forward_invite_dateinput").datepicker("destroy");
				jQ("#forward_invitetime_close").unbind("click");
				jQ("#forward_invitetime_confirm").unbind("click");
				jQ("#forward_invite_list").empty();
				jQ("#loadingui").hide();
				var shareid=dataObj.shareid;
				var title=dataObj.title;
				var starttime=dataObj.starttime;
				var trobj=jQ("tr[eventid="+eventid+"]");
				var tdobj=trobj.find("td.theme");
				var zonecontentobj=tdobj.find("div.zonecontent");
				var imgobj=dataObj.clipeventpic;
				var visiturl=jQ("#ctxVal").val()+"/myclip/clip_detail.html?"+shareid;
				jQ("#add_return a.close").unbind("click").bind("click",function(){
					zonecontentobj.hide(visiturl);
					jQ("#add_return_wrap").hide();
					window.open();
				});
				jQ("#add_return div.btnline button").unbind("click").bind("click",function(){
					zonecontentobj.hide();
					jQ("#add_return_wrap").hide();
					window.open(visiturl);
				});
				jQ("#add_return_vcode_ipt").bind("focus",function(){
					if(!jQ(this).hasClass("onfocus")){
						jQ(this).val("");
						jQ(this).addClass("onfocus");
					}
				});
				jQ("#add_return_vcode_ipt").bind("blur",function(){
					if(jQ.trim(jQ(this).val()).length==0){
						jQ(this).val("4位数字");
						jQ(this).removeClass("onfocus");
					}
				});
				jQ("#add_return_vcode_ipt").data("eventid",dataObj.eventid);
				jQ("#add_return_vcode").show();
				jQ("#add_return_visit_url").val("http://"+document.domain+visiturl);
				initForwardClipboardOpt();
				if(invitetime>0){
					initShareOutofSite(shareid,title,invitetime,imgobj);
				}else{
					initShareOutofSite(shareid,title,starttime,imgobj);
				}
				jQ("#add_return_wrap").show();
				//跳转至详情页面
			}else{
				clip_tips(dataObj.msg);
			}
			
		}
	});
}

function initForwardClipboardOpt(){
	var clip = new ZeroClipboard( document.getElementById("add_return_copybtn"), {
		moviePath: jQ("#ctxVal").val()+"/js/common/ZeroClipboard.swf",
		positionStyle:"fixed"
	});
	clip.addEventListener("complete",function(){
		copyOptReturnBox(jQ("#add_return_copybtn"),"复制成功");
	});
}

function copyOptReturnBox(obj,content){
	var obj_box = jQ(obj);
	var obj_offset = obj_box.offset();
	var msg_box = jQ("#accept_msg_box");
	jQ("#accept_msg_box_content").empty().append(content);
	var _top = obj_offset.top - msg_box.outerHeight()/2 ;
	var _left = obj_offset.left - msg_box.outerHeight()/2;
	msg_box.css({"top":_top+"px","left":_left+"px"}).show();
	msg_box.find("div.msg_note").animate({top: 20+'px'}, 500,function(){
		setTimeout(function(){
			msg_box.find("div.msg_note").animate({top: 100+'px'},500,function(){msg_box.hide();});
		},2000);
	});
}

function submitForwardVCode(obj){
	if(!jQ("#add_return_vcode_ipt").hasClass("onfocus")){
		clip_tips("请输入验证码");
		return;
	}
	var vcode=jQ.trim(jQ("#add_return_vcode_ipt").val());
	var p = /^[0-9]{4}$/; 
	if(!p.test(vcode)){
		clip_tips("请输入4位数字");
		return;
	}
	jQ(obj).hide();
	var eventid=eval(jQ("#add_return_vcode_ipt").data("eventid"));
	jQ.ajax({
		type: "POST",
		url:"eventAjax!submitVCode.action",
		data:{
			eventid:eventid,
			vcode:vcode
		},
		success:function(data){
			
			if(data.result){
				jQ("#add_return_vcode_ipt").attr("disabled",true);
			}else{
				clip_tips(data.errormsg);
			}
		}
	});
}

function initShareOutofSite(shareid,title,beginlong,imgobj){
	var eventshareid=shareid;
	var eventtitle=title;
	var eventstarttime=beginlong;
	var day=new Date();
	day.setTime(eventstarttime);
	var startstr=day.pattern("yyyy年MM月dd日");
	jQ("#add_return div.outsitelogo a").unbind("click");
	jQ("#add_return div.outsitelogo a.renren").bind("click",function(){
		var url="http://"+document.domain+jQ("#ctxVal").val()+"/myclip/clip_detail.html?"+eventshareid;
		var img="";
		if(imgobj!=null&&imgobj.length>0){
			img="http://"+document.domain+jQ("#ctxVal").val()+"/clippic/"+imgobj;
		}
		var rrShareParam = {
			resourceUrl : url,	//分享的资源Url
			srcUrl :url,	//分享的资源来源Url,默认为header中的Referer,如果分享失败可以调整此值为resourceUrl试试
			pic : img,		//分享的主题图片Url
			title : '档期分享：'+startstr+'  '+title,		//分享的标题
			description : '更多详情请点击'	//分享的详细描述
		};
		var temp = [];
		for( var p in rrShareParam ){
			temp.push(p + '=' + encodeURIComponent( rrShareParam[p] || '' ) )
		}
		
		
		window.open(
		'http://widget.renren.com/dialog/share?' + temp.join('&'),
		'_blank'); 
	});
	
	jQ("#add_return div.outsitelogo a.kaixin").bind("click",function(){
		var url="http://"+document.domain+jQ("#ctxVal").val()+"/myclip/clip_detail.html?"+eventshareid;
		window.open(
		'http://www.kaixin001.com/repaste/share.php?rurl='+url
		+'&rtitle=档期分享'
		+'&rcontent='+startstr+'  '+eventtitle+'    '+'更多详情请点击',
		'_blank',
		'height=500,width=700,top=200,left=410,toolbar=no,menubar=no,scrollbars=no,resizable=no,location=no, status=no');
		
	});
	
	jQ("#add_return div.outsitelogo a.sina").bind("click",function(){
		var url="http://"+document.domain+jQ("#ctxVal").val()+"/myclip/clip_detail.html?"+eventshareid;
		var img="";
		if(imgobj!=null&&imgobj.length>0){
			img="http://"+document.domain+jQ("#ctxVal").val()+"/clippic/"+imgobj;
		}
		var param = {
		    url:url,
		    type:'3',
		    title:'档期分享：'+startstr+'  '+eventtitle+'    '+'更多详情请点击',
		    pic:img,
		    ralateUid:'2618696840',
			language:'zh_cn',
		    rnd:new Date().valueOf()
		  };
		var temp = [];
		for( var p in param ){
			temp.push(p + '=' + encodeURIComponent( param[p] || '' ) )
		}
		window.open(
				'http://service.weibo.com/share/share.php?' + temp.join('&') ,
				'_blank',
		'height=520,width=607,top=150,left=410,toolbar=no,menubar=no,scrollbars=no,resizable=no,location=no, status=no');
	});
	jQ("#add_return div.outsitelogo a.douban").bind("click",function(){
		var url="http://"+document.domain+jQ("#ctxVal").val()+"/myclip/clip_detail.html?"+eventshareid;
		window.open(
		'http://www.douban.com/recommend/?url='+url
		+'&title=档期分享'+
		+'&comment='+startstr+'  '+eventtitle+'    '+'更多详情请点击',
		'_blank',
		'height=370,width=505,top=300,left=450,toolbar=no,menubar=no,scrollbars=no,resizable=no,location=no, status=no');
	});
	jQ("#add_return div.outsitelogo a.weixin").bind("click",function(){
//		var detailurl="http://"+document.domain+jQ("#ctxVal").val()+"/myclip/clip_detail.html?"+eventshareid;
//		var img="";
//		if(imgobj!=null&&imgobj.length>0){
//			img="http://"+document.domain+jQ("#ctxVal").val()+"/clippic/"+imgobj;
//		}
		init2weixinbox(eventshareid);
	});
	jQ("#add_return div.outsitelogo a.tqq").bind("click",function(){
		var url="http://"+document.domain+jQ("#ctxVal").val()+"/myclip/clip_detail.html?"+eventshareid;
		var img="";
		if(imgobj!=null&&imgobj.length>0){
			img="http://"+document.domain+jQ("#ctxVal").val()+"/clippic/"+imgobj;
		}
		var param = {
		    url:url,
		    appkey:'',
		    title:'档期分享：'+startstr+'  '+title+'    '+'更多详情请点击',
		    pic:img,
		    site:'www.clip24.cn'
		  };
		var temp = [];
		for( var p in param ){
			temp.push(p + '=' + encodeURIComponent( param[p] || '' ) )
		}
		var _u = 'http://v.t.qq.com/share/share.php?'+ temp.join('&');
		window.open( _u,'转播到腾讯微博', 'width=700, height=680, top=0, left=0, toolbar=no, menubar=no, scrollbars=no, location=yes, resizable=no, status=no' );
	});
}

function showContactDetailTip(obj,eventid){
	if(jQ("#addclipcontactlist").css("display")=="none"){
		var btnobj=jQ(obj);
		jQ("#addclipcontactlist").data("eventid",eventid);
//		var chooseobj=.parent();
//		var zonecontentid=chooseobj.parent().attr("id");
		jQ("#addclipcontactmbtab span:first").removeClass().addClass("onit").show();
		jQ("#addclipcontactmbtab span:last").removeClass().addClass("nor");
		jQ("#contact").show();
		jQ("#inv_congroup li dt b.tipexpand").removeClass("hidebg");
		jQ("#inv_congroup li dt b.tipexpand").unbind("click").bind("click",add_clipOpenClose2);
		
		jQ("#contact_friend dt a:first").attr("class","no_sel");
		jQ("#inv_congroup").hide();
		jQ("#inv_congroup li dt a[class!='dis_sel']").removeClass().addClass("no_sel");
		jQ("#inv_congroup li dd div.check  a").attr("class","no_sel");
		jQ("#contact_friend dd div.check  a").attr("class","no_sel");
		
		var listcontent=jQ(obj).parent().prevAll("li");
		var contactlength=listcontent.length;
		if(contactlength>0){
			if(jQ("#contact_friend dd").length==contactlength){
				clip_tips("您已经邀请了所有好友一起参加。");
				return;
				//jQ("#contact_friend dt a[class!='dis_sel']").removeClass().addClass("all_sel");
			}
//			jQ("#inv_congroup li dt a").removeClass().addClass("half_sel");
			listcontent.each(function(){
				var uid=eval(jQ(this).find("input.uid").val());
				jQ("#contact_friend>dd[uid='uid_"+uid+"']>div.check>a").attr("class","all_sel").addClass("dissel_sel");
				jQ("#inv_congroup>li>dd[uid='uid_"+uid+"']>div.check>a").attr("class","all_sel").addClass("dissel_sel");
			});
//			checkAllGroupList(true);
//			checkAllContacList(true);
			jQ("#inv_congroup li").each(function(){
				if(!jQ(this).find("dt").find("a").hasClass("dis_sel")){
					if(jQ(this).find("dd").find("div.check").find("a.dissel_sel").length==jQ(this).find("dd").length){
						jQ(this).find("dt").find("a").removeClass().addClass("dissel_sel");
					}else{
						if(jQ(this).find("dd").find("div.check").find("a.dissel_sel").length>0)
							jQ(this).find("dt").find("a").removeClass().addClass("half_sel");
					}
				}
			});
			if(jQ("#contact_friend dd").find("div.check").find("a.dissel_sel").length==jQ("#contact_friend dd").length){
				jQ("#contact_friend dt").find("a").removeClass().addClass("dissel_sel");
			}else{
				if(jQ("#contact_friend dd").find("div.check").find("a.dissel_sel").length>0)
					jQ("#contact_friend dt").find("a").removeClass().addClass("half_sel");
			}
		}
		var box = jQ(obj).offset();
		jQ("#addclipcontactlist").css({"top":box.top-40,"left":box.left+30}).show();
		jQ("#addclipcontactlist").show();
																/***1***/
		jQ("#contact_friend dt a").unbind("click").bind("click",selAllsynchronizecontactlistOnContact);
																			/***2***/
		jQ("#contact_friend dd a").unbind("click").bind("click",synchronizecontactlistOnContact);
																/***3***/
		jQ("#inv_congroup li dt a").unbind("click").bind("click",selAllsynchronizecontactlistOnGroup);
																						/***4***/
		jQ("#inv_congroup li dd.contactelement a").unbind("click").bind("click",synchronizecontactlistOnGroup);
		
		var btnline=jQ("#chosen_friend").next("div.btnline");
		btnline.find("button.confirm").unbind("click").bind("click",function(){
			jQ("#loadingui").show();
			jQ("#chosen_friend").parent().hide();
			var addcontactlist="";
			var addcontactmobilelist="";
			jQ("#chosen_friend").find("li").each(function(){
				var ulstr=jQ(this).attr("uid");
				var ularr=ulstr.split("_");
				if(addcontactlist.length<=0){
					addcontactlist+=ularr[1];
				}else{
					addcontactlist+=","+ularr[1];
				}
				if(jQ(this).find("i.onit").length>0){
					if(addcontactmobilelist.length<=0){
						addcontactmobilelist+=ularr[1];
					}else{
						addcontactmobilelist+=","+ularr[1];
					}
				}
			});
			var eventid=eval(jQ("#addclipcontactlist").data("eventid"));
			jQ.ajax({
				type:"POST",
				url: "shareAjax!forwardMoreWithShareEvent.action",
				data:{
					eventid:eventid,
					share2userlist:addcontactlist,
					mlist:addcontactmobilelist
				},
				success:function(data){
					if(data!=null){
						var dataObj=eval("("+data+")");//转换为json对象
						if(dataObj.result){
							close_Addclipcontactlist_Dialog();
							jQ("#chosen_friend").empty();
							jQ("#loadingui").hide();
							clip_tips("添加成功");
							addDetailContent(jQ("#clipevent-"+eventid));
						}else{
							clip_tips(dataObj.msg);
						}
					}
				}
			});
		});
	}else{
		jQ("#addclipcontactlist").hide();
		jQ("#addclipcontactlist").removeData("eventid");
	}
	
}
		/***1***/
function selAllsynchronizecontactlistOnContact(event){
//	var zonecontentid=event.data.zonecontentid;
	if(jQ(this).hasClass("dis_sel"))
		return;
	if(jQ(this).hasClass("dissel_sel"))
		return;
	if(jQ(this).hasClass("all_sel")){
		jQ("#contact_friend dd div.check a:not([class$='dissel_sel'])").each(function(){
			jQ(this).attr("class","no_sel");
			var uid=eval(jQ(this).nextAll("input.uid").val());
			jQ("#inv_congroup li dd[uid='uid_"+uid+"'] div.check a[uid='"+uid+"']").attr("class","no_sel");
			removeContactarea(uid);
		});
		checkAllGroupList(false);
		if(jQ("#contact_friend dd div.check a:not([class$='dissel_sel'])").length==jQ("#contact_friend dd div.check a").length)
			jQ(this).removeClass().addClass("no_sel");
		else
			jQ(this).removeClass().addClass("half_sel");
	}else{
		jQ("#contact_friend dd div.check a:not([class$='dissel_sel'])").each(function(){
			jQ(this).attr("class","all_sel");
			var uid=eval(jQ(this).nextAll("input.uid").val())	;
			var hasmobile=eval(jQ(this).nextAll("input.hasmobile").val());
			var name=jQ(this).parent().nextAll("div.name").text();
			var logo=jQ(this).parent().nextAll("a").find("img").attr("src");
			jQ("#inv_congroup li dd[uid='uid_"+uid+"'] div.check a[uid='"+uid+"']").attr("class","all_sel");
			showQuickContact(1,uid,name,logo,hasmobile);
		});
		checkAllGroupList(true);
		jQ(this).removeClass().addClass("all_sel");
	}
}
		/***2***/
function synchronizecontactlistOnContact(event){
//	var zonecontentid=event.data.zonecontentid;
	var cbxobj=jQ(this);
	if(cbxobj.hasClass("dissel_sel"))
		return;
	var cbxval=cbxobj.hasClass("all_sel");
	var uid=cbxobj.nextAll("input.uid").val();
	var hasmobile=eval(cbxobj.nextAll("input.hasmobile").val());
	var name=cbxobj.parent().nextAll("div.name").text();
	var logo=cbxobj.parent().nextAll("a").find("img").attr("src");
	if(cbxval){
		cbxobj.removeClass("all_sel").addClass("no_sel");
		jQ("#inv_congroup li dd[uid='uid_"+uid+"'] div.check a[uid='"+uid+"']").attr("class","no_sel");
		removeContactarea(uid);
		checkAllContacList(false);
		checkAllGroupList(false);
	}else{
		cbxobj.removeClass("no_sel").addClass("all_sel");
		jQ("#inv_congroup li dd[uid='uid_"+uid+"'] div.check a[uid='"+uid+"']").attr("class","all_sel");
		showQuickContact(1,uid,name,logo,hasmobile);
		checkAllContacList(true);
		checkAllGroupList(true);
	}
}
		/***3***/
function selAllsynchronizecontactlistOnGroup(event){
//	var zonecontentid=event.data.zonecontentid;
	if(jQ(this).hasClass("dis_sel"))
		return;
	if(jQ(this).hasClass("dissel_sel"))
		return;
	if(jQ(this).hasClass("all_sel")){
		jQ(this).parent().nextAll("dd").each(function(){
			var checkboxobj=jQ(this).find("div.check").find("a.all_sel");
			if(checkboxobj.hasClass("dissel_sel"))
				return true;
			checkboxobj.removeClass("all_sel").addClass("no_sel");
			var uid=eval(checkboxobj.nextAll("input.uid").val());
			removeContactarea(uid);
			jQ("#inv_congroup li dd[uid='uid_"+uid+"'] div.check a[uid='"+uid+"']").attr("class","no_sel");
			jQ("#contact_friend dd[uid='uid_"+uid+"'] div.check a[uid='"+uid+"']").attr("class","no_sel");
		});
		checkAllGroupList(false);
		checkAllContacList(false);
	}else{
		jQ(this).parent().nextAll("dd").each(function(){
			var checkboxobj=jQ(this).find("div.check").find("a");
			if(!checkboxobj.hasClass("no_sel"))
				return true;
			checkboxobj.removeClass("no_sel").addClass("all_sel");
			var uid=eval(checkboxobj.nextAll("input.uid").val());
			var hasmobile=eval(checkboxobj.nextAll("input.hasmobile").val());
			var name=checkboxobj.parent().nextAll("div.name").text();
			var logo=checkboxobj.parent().nextAll("a").find("img").attr("src");
			showQuickContact(1,uid,name,logo,hasmobile);
			
			jQ("#inv_congroup li dd[uid='uid_"+uid+"'] div.check a[uid='"+uid+"']").attr("class","all_sel");
			jQ("#contact_friend dd[uid='uid_"+uid+"'] div.check a[uid='"+uid+"']").attr("class","all_sel");
		});
		checkAllGroupList(true);
		checkAllContacList(true);
	}
}
		/***4***/
function synchronizecontactlistOnGroup(event){
	var cbxobj=jQ(this);
	if(cbxobj.hasClass("dissel_sel"))
		return;
//	var zonecontentid=event.data.zonecontentid;
	var cbxval=cbxobj.hasClass("all_sel");
	var uid=eval(cbxobj.nextAll("input.uid").val());
	var hasmobile=eval(cbxobj.nextAll("input.hasmobile").val());
	var name=cbxobj.parent().nextAll("div.name").text();
	var logo=cbxobj.parent().nextAll("a").find("img").attr("src");
	if(cbxval){
		cbxobj.removeClass("all_sel").addClass("no_sel");
		jQ("#inv_congroup li dd[uid='uid_"+uid+"'] div.check a[uid='"+uid+"']").attr("class","no_sel");
		jQ("#contact_friend dd[uid='uid_"+uid+"'] div.check a[uid='"+uid+"']").attr("class","no_sel");
		removeContactarea(uid);
		checkAllGroupList(false);
		checkAllContacList(false);
	}else{
		cbxobj.removeClass("all_sel").addClass("all_sel");
		jQ("#inv_congroup li dd[uid='uid_"+uid+"'] div.check a[uid='"+uid+"']").attr("class","all_sel");
		jQ("#contact_friend dd[uid='uid_"+uid+"'] div.check a[uid='"+uid+"']").attr("class","all_sel");
		showQuickContact(1,uid,name,logo,hasmobile);
		checkAllGroupList(true);
		checkAllContacList(true);
	}
}

function add_clipOpenClose2(){
	if(!jQ(this).prev().hasClass("dis_sel")){
		jQ(this).parent().nextAll().slideToggle('fast');
		jQ(this).toggleClass('close');
	}
}

function checkAllContacList(ischecktrue){
	if(jQ("#contact_friend dd").length==0)
		return;
	if(jQ("#contact_friend dt").find("a").hasClass("dissel_sel"))
		return;
	if(ischecktrue){
		if(jQ("#contact_friend dd").find("div.check").find("a.all_sel").length==jQ("#contact_friend dd").length){
			jQ("#contact_friend dt").find("a").removeClass().addClass("all_sel");
		}else{
			if(jQ("#contact_friend dd").find("div.check").find("a.all_sel").length>0)
				jQ("#contact_friend dt").find("a").removeClass().addClass("half_sel");
		}
	}else{
		if(jQ("#contact_friend dd").find("div.check").find("a.no_sel").length==jQ("#contact_friend dd").length){
			jQ("#contact_friend dt").find("a").removeClass().addClass("no_sel");
		}else{
			if(jQ("#contact_friend dd").find("div.check").find("a.all_sel").length>0)
				jQ("#contact_friend dt").find("a").removeClass().addClass("half_sel");
		}
	}
}

function checkAllGroupList(ischecktrue){
	if(ischecktrue){
		jQ("#inv_congroup li").each(function(){
			if(jQ(this).find("dt").find("a").hasClass("dissel_sel"))
				return true;
			if(!jQ(this).find("dt").find("a").hasClass("dis_sel")){
				if(jQ(this).find("dd").find("div.check").find("a.all_sel").length==jQ(this).find("dd").length){
					jQ(this).find("dt").find("a").removeClass().addClass("all_sel");
				}else{
					if(jQ(this).find("dd").find("div.check").find("a.all_sel").length>0)
						jQ(this).find("dt").find("a").removeClass().addClass("half_sel");
				}
			}
		});
	}else{
		jQ("#inv_congroup li").each(function(){
			if(jQ(this).find("dt").find("a").hasClass("dissel_sel"))
				return true;
			if(!jQ(this).find("dt").find("a").hasClass("dis_sel")){
				if(jQ(this).find("dd").find("div.check").find("a.no_sel").length==jQ(this).find("dd").length){
					jQ(this).find("dt").find("a").removeClass().addClass("no_sel");
				}else{
					if(jQ(this).find("dd").find("div.check").find("a.all_sel").length>0)
						jQ(this).find("dt").find("a").removeClass().addClass("half_sel");
				}
			}
		});
	}
}

function removeContactarea(uid){
	jQ("#chosen_friend").find("li[uid=uid_"+eval(uid)+"]").remove();
	if(jQ("li",jQ("#chosen_friend")).length==0){
		jQ("#chosen_friend").parent().hide();
	}
}

function showQuickContact(isNormal,id,name,logourl,hasmobile){
	if(isNormal){
		var flag=false;
		if(jQ("#chosen_friend").parent().css("display")=="none"){
			flag=true;
		}
		var canbeadd=true;
		jQ("li",jQ("#chosen_friend")).each(function(){
			if(jQ(this).attr("uid")=="uid_"+id){
				canbeadd=false;
				return false;
			}
		});
		if(!canbeadd)
			return;
		var html="<li uid='uid_"+id+"'>";
		html+="<div style=\"background:url('"+logourl+"')\"></div>";
		html+="<span title='"+name+"'>"+name+"</span>";
		if(hasmobile)
			html+="<i title='短信提醒'></i>";
		html+="</li>";
		jQ("#chosen_friend").append(html);
		jQ("#chosen_friend li").find("i").unbind("click").bind("click",function(){
			jQ(this).toggleClass("onit");
		});
		if(flag)
			jQ("#chosen_friend").parent().show();
	}
}
